package com.grandbroad.eim.ui.activities;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.login.bean.User;
import com.easy.west.westclient.api.vod.bean.CollectList;
import com.easy.west.westclient.api.vod.event.GetColloectListEvent;
import com.grandbroad.eim.R;
import com.grandbroad.eim.adapter.ColloectVodAdapter;
import com.grandbroad.eim.app.MyApplication;
import com.grandbroad.eim.base.BaseActivity;
import com.grandbroad.eim.utils.CacheUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 收藏页面
 * 部分页面为标注作用
 * 请根据英文理解意思或者前往app域查看事件注册的注释和清单文件里查看
 * (zao dian li zhi,nian zong shao,gui ju hai duo)
 */
public class CollectActivity extends BaseActivity {
    @BindView(R.id.img_back_btn)
    ImageView imgBackBtn;
    @BindView(R.id.tv_toolbar_title)
    TextView tvToolbarTitle;
    @BindView(R.id.tool_bar)
    Toolbar toolBar;
    @BindView(R.id.recycler_collectlist)
    RecyclerView recyclerCollectlist;
    private ColloectVodAdapter vodAdapter;
    private User user;
    @Override
    protected void initview() {
        vodAdapter = new ColloectVodAdapter();
        if (user.getAccess_token().equals(CacheUtils.getUser().getAccess_token()))
        {
            tvToolbarTitle.setText("我的收藏");

        }
        else
        {
            tvToolbarTitle.setText(user.getName()+"的收藏");
        }
        toolBar.setBackgroundColor(Color.WHITE);
        recyclerCollectlist.setLayoutManager(new LinearLayoutManager(this));
        recyclerCollectlist.setAdapter(vodAdapter);
        setBackBtn(imgBackBtn);
    }

    @Override
    protected void initdata() {
        user = (User) getIntent().getSerializableExtra("bean");
        //请求
        MyApplication.getMoleclient().getCollectList(user.getId());
    }

    @Override
    protected int setlayout() {
        return R.layout.activity_collect;
    }

    /**
     * 获取收藏列表
     * @param eva
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getColleoctList(GetColloectListEvent eva)
    {
        if(eva.isOk())
        {
            CollectList list = eva.getBean();
            if (list.getStatus()==1)
            {
                vodAdapter.setDataBeanList(list.getData());
                vodAdapter.notifyDataSetChanged();
            }
        }

    }


}
